<?php
/**
 * 后台专有的
 */
namespace backend\models;

use Yii;
use common\models\discount\FullCutSet;

/**
 * This is the model class for table "full_cut".
 *
 * @property integer $full_cut_id
 * @property string $title
 * @property integer $c_obj
 * @property integer $c_type
 * @property string $begin_time
 * @property string $end_time
 * @property integer $c_status
 * @property string $create_time
 */
class FullCut extends \common\models\discount\FullCut
{
    
    public function beforeSave($insert) {
        if($insert) {
            $this->create_time = date("Y-m-d H:i:s");
        }
        return  parent::beforeSave($insert);
    }
    
    public function afterSave($insert, $changedAttributes) {
        if(!$insert) {
            FullCutSet::deleteAll(['full_cut_id'=>$this->full_cut_id]);
        }
        
        foreach ($this->total_amount as $key=>$val) {
            $model = new FullCutSet();
            $model->full_cut_id = $this->full_cut_id;
            $model->discount_amount = $this->discount_amount[$key];
            $model->total_amount = $val;
            if($model->validate()){
                $model->save();
            }
        }
    
        return  parent::afterSave($insert, $changedAttributes);
    }
   
}
